package cn.bellychang.leetcode.question088;

/**
 * @author ChangLiang
 * @date 2021/3/7
 */
public class Solution4 {

    public void merge(int[] nums1, int m, int[] nums2, int n) {

        for(int i=0; i<n; i++){
            nums1[m+i] = nums2[i];
        }

        for(int i = m; i<m+n; i++){
            int current = i;
            int prev = i-1;
            while(prev>=0 && nums1[prev] > nums1[current]){
                swap(current, prev, nums1);
                prev--;
                current--;
            }
        }
    }

    private void swap(int i, int j, int[] nums1){
        int temp = nums1[i];
        nums1[i] = nums1[j];
        nums1[j] = temp;
    }
}
